// package1/pages/pile/list.js
import service from '../../../utils/request'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    time: '',
    visibel: false,
    info: {},
    start: "",
    chargeOrder:{},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },
  onClose(){
    this.setData({
      visibel: false
    })
  },
  showWait(){
    if(this.data.info.online !=1){
      wx.showToast({
        title: '充电桩离线，不能进行此操作',
        icon: "none"
      })
      return
    }
    this.setData({
      visibel: true
    })
  },
  bindTimeChange(e){
    this.setData({
      time: e.detail.value
    })
  },
  personOrder(){
    wx.navigateTo({
      url: '/package1/pages/order/order',
    })
  },
  myCombo(){
    wx.navigateTo({
      url: '/package1/pages/combo/index',
    })
  },
  repair(){
    wx.navigateTo({
      url: '/package1/pages/repair/index',
    })
  },
  agreement(){
    wx.navigateTo({
      url: '/package1/pages/pile/pile',
    })
  },
  publiShip(){
    wx.navigateTo({
      url: '/package1/pages/person/pub',
    })
  },
  //开始充电
  charge(){
    let that = this
    if(!this.data.info.online){
      wx.showToast({
        title: '充电枪离线，不能进行此操作',
        icon: 'none'
      })
      return
    }
    service("GET","/personal/pile/start").then(res => {
     console.log('开始充电', res)
     if(res.data.code ==0){
       wx.navigateTo({
         url: '/package1/pages/order/personal?oid='+res.data.oid,
       })
     }else{
       wx.showToast({
         title: res.data.msg,
         icon: 'none'
       })
     }
     
    })
  },
      //预约充电
  waitCharge(){
    let that = this
    let data = this.data.time
    if(!data){
      wx.showToast({
        title: '请选择预约时间',
      })
    }
    let strs=data.split(":")
    let hour = strs[0], minute = strs[1], second = '00'
    let time = hour +':'+ minute +':'+ second
    service("POST","/personal/pile/order", { time }).then(res => {
      console.log('预约充电', res)
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})